package org.example.zpqy.controll;

import org.example.zpqy.bean.AppleOne;
import org.example.zpqy.service.AppleOneService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/appleone")
public class AppleOneController {

    private final AppleOneService service;

    public AppleOneController(AppleOneService service) {
        this.service = service;
    }

    // 查询全部
    @GetMapping("/all")
    public List<AppleOne> getAll() {
        return service.findAll();
    }

    // 按属性查询，比如 /api/appleone/氮含量
    @GetMapping("/{attribute}")
    public AppleOne getByAttribute(@PathVariable String attribute) {
        return service.findByAttribute(attribute);
    }

    // 保存或更新
    @PostMapping("/save")
    public AppleOne save(@RequestBody AppleOne appleOne) {
        return service.save(appleOne);
    }
}
